extends Node

var inventory = Inventory.new()

func _ready():
	print("InventoryManager 准备就绪")  # 调试信息
	process_mode = Node.PROCESS_MODE_ALWAYS

func add_item(item_id: String, amount: int = 1) -> bool:
	print("尝试获取物品 ", item_id, " amount: ", amount)  # 调试信息
	var item = ItemDatabase.get_item(item_id)
	if item:
		print("从数据库获得物品: ", item.name)  # 调试信息
		var success = inventory.add_item(item, amount)
		print("添加物品成功: ", success)  # 调试信息
		print_inventory()
		return success
	print("从数据库获取物品失败: ", item_id)  # 调试信息
	return false

func remove_item(item_id: String, amount: int = 1) -> bool:
	var item = ItemDatabase.get_item(item_id)
	if item:
		return inventory.remove_item(item, amount)
	return false 

# 新增：打印背包中所有物品的函数
func print_inventory() -> void:
	# 遍历 inventory 中所有槽位并打印槽位内物品的名称和数量
	for slot in inventory.slots:
		if slot.item:
			print("物品: ", slot.item.name, " 数量: ", slot.amount)
		else:
			print("空槽位")
